﻿@using CNKI.TPI.Web.Search.Model;
@using CNKI.TPI.Web.Base;
<script>
    $(function () {
        SearchDB();
    })
    function modifydbauth(dbid) {

        ajaxLoad("initload", '@Html.Raw(Url.Action("DBAuthManager", "Admin_User"))?dbid=' + dbid + '&id=' + $("#GroupUserID").val() + '&flage=' + $("#Flage").val());
    }
    $(document).keydown(function (event) {
        if (event.keyCode == 13) {
            SearchDB();
        }
    });
    function SearchDB() {
        $("#pageIndexNow").val(1);
        var searchname = $("#dbname").val();
        $("#hiddendbname").val(searchname);
        LoadData();
    }
    function searchPageNew(n) {
        $("#pageIndexNow").val(n);
        LoadData();

    }
    function LoadData() {
        var dbuserid = $("#GroupUserID").val();
        var flage = $("#Flage").val();           //flage  1代表用户组数据库权限，0代表用户数据库权限设置
        $.ajax({
            type: "GET",
            url: timestamp("@Html.Raw(Url.Action("DBAuthResult", "Admin_User"))"),
            data: { "id": dbuserid, "flage": flage, "pageIndexNow": $("#pageIndexNow").val(), "dbName": $("#hiddendbname").val() },
            beforeSend: function () { $("#loading").show(); },
            success: function (msg) {
                $("#dbList").html("");
                $("#dbList").html(msg);
                $("#loading").hide();
            },
            error: function (e)
            { $("#loading").hide(); }
        })
    }


    function allauth() {
        disablesave();
        var urlstr = "@Html.Raw(Url.Action("AllAuth", "Admin_User"))";
        var datainfo = { "id": $("#GroupUserID").val(), "flage": $("#Flage").val() };
        dealdata(urlstr, datainfo);
    }
    function thisauth() {
        disablesave();
        //数据库选中列表
        var jsondbid = [];//用户组
        $(".checkboxdb input[type='checkbox']:checked").each(function () {
            jsondbid.push($(this).val());
        })
        if (jsondbid.length == 0) {
            messageAlert("请先选择数据库！");
            enablesave();
            return;
        }
        var urlstr = "@Html.Raw(Url.Action("ThisAuth", "Admin_User"))";
        var datainfo = { "id": $("#GroupUserID").val(), "dbid": jsondbid.toString(), "flage": $("#Flage").val() };
        dealdata(urlstr, datainfo);

    }
    //调用controll
    function dealdata(urlstr, datastr) {

        $.ajax({
            type: "GET",
            url: timestamp(urlstr),
            data: datastr,
            beforeSend: function () { $("#loading").show(); },
            success: function (m) {
                if (m == "True") {
                    messageAlert("操作成功！");
                    ajaxLoad("initload", '@Html.Raw(Url.Action("DBAuthList", "Admin_User"))?id=' + $("#GroupUserID").val() + '&flage=' + $("#Flage").val());
                }
                else {
                    messageAlert("操作失败！");
                }
                enablesave();
                $("#loading").hide();
            },
            error: function (e) {
                enablesave();
                $("#loading").hide();
                messageAlert("操作失败！");
            }
        })

    }
    function disablesave() {
        $(".btn-defa-f").attr("disabled", "disabled");
    }
    function enablesave() {
        $(".btn-defa-f").removeAttr("disabled", "disabled");
    }
</script>
<h3 class='box-h'>数据库权限设置</h3>
<div class="wrapR-h">
    <input type="hidden" id="GroupUserID" value="@ViewBag.GroupUserID"/>
    <input type="hidden" id="Flage" value="@ViewBag.Flage"/>
    <div class="form form-h">
        <input type="hidden" id="pageIndexNow" name="pageIndexNow" value="1" />
        <input type="hidden" id="searchflage" value="1" />
        <div class="f-gp" style="padding-top: 20px">
            <div class="f-lb">
                <label class="f-label">数据库名称：</label>
            </div>
            <div class="f-ct f-ml">
                <input type="text" class="f-text span4" id="dbname" maxlength="255">
                <input type="hidden" class="f-text span4" id="hiddendbname">
                <a class="btn btn-submit btn-warn-f" onclick="SearchDB()">检索</a>
            </div>


        </div>
    </div>

</div>

<div id="dbList">
</div>
<div class='posr'>
    <button class="btn btn-m btn-submit btn-defa-f" onclick="allauth()">所有库所有权限</button>
    <button class="btn btn-m btn-submit btn-defa-f" onclick="thisauth()">当前库所有权限</button>
    @if (ViewBag.Flage == 1)
    {
        <button class="btn btn-m btn-prim-f"  href="javascript:void(0);" onclick="ajaxLoad('initload','@Html.Raw(Url.Action("GroupIndex", "Admin_User"))')">返回</button>

    }
    else
    {
        <button class="btn btn-m btn-prim-f"  href="javascript:void(0);" onclick="ajaxLoad('initload','@Html.Raw(Url.Action("UserIndex", "Admin_User"))')">返回</button>
    }
</div>
